package com.tcxhb.job.agent.server.command.impl;

import com.tcxhb.job.agent.server.command.CommandHandler;
import com.tcxhb.job.agent.server.command.CommandMapping;
import com.tcxhb.job.agent.server.command.CommandRequest;
import com.tcxhb.job.agent.server.thread.JobRunThread;
import com.tcxhb.job.common.model.MiscResult;
import com.tcxhb.job.common.model.job.JobContext;
import com.tcxhb.job.common.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @Auther: tcxhb
 * @Date: 2023/11/5
 */
@Component
@Slf4j
@CommandMapping(name = "/cmd/job/run", desc = "执行任务")
public class JobRunCommand implements CommandHandler<Boolean> {
    @Autowired
    private JobRunThread jobRunThread;

    @Override
    public MiscResult<Boolean> handle(CommandRequest request) {
        log.info("agent-run-cmd:" + JsonUtils.toJson(request.getParameters()));
        String params = JsonUtils.toJson(request.getParameters());
        JobContext context = JsonUtils.toBean(params, JobContext.class);
        return jobRunThread.submit(context);
    }
}
